{% extends "base.html" %}

{% block title %}公司主页 - 机构调研报告{% endblock %}

{% block page_title %}{{ company.stock_name }} - 机构调研报告{% endblock %}
{% block page_subtitle %}{{ company.stock_name }}（{{ company.stock_code }}）{{ '沪市' if market == 'sh' else '深市' }}上市公司机构调研信息{% endblock %}

{% block extra_css %}
<style>
    /* 整体布局 */
    .company-container { padding: 1rem 1.5rem; max-width: 1200px; margin: 0 auto; }
    
    /* Tabs */
    .tabs { margin-bottom: 1rem; }
    .tab-link { margin-right: 12px; padding: 6px 12px; border-radius: 16px; text-decoration: none; }
    .tab-active { background: #8b7355; color: #fff; }
    .tab-inactive { background: #eee; color: #333; }
    
    /* 公司头部 */
    .company-header { background: #f8f4e3; border-radius: 12px; padding: 1.5rem; margin-bottom: 2rem; display: flex; align-items: center; gap: 1rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
    .company-avatar { width: 48px; height: 48px; border-radius: 50%; background: #eee; object-fit: cover; }
    .company-info h2 { margin: 0; color: #5d4e37; font-size: 1.5rem; }
    .company-info p { margin: 0.25rem 0 0; color: #888; font-size: 1rem; }
    
    /* 部分标题 */
    .section-title { font-size: 1.25rem; color: #8b7355; margin: 2rem 0 1rem; border-bottom: 2px solid #f0ead6; padding-bottom: 0.5rem; }
    
    /* 卡片列表 */
    .card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
    .card { background: #fff; border: 1px solid #f0ead6; border-radius: 12px; padding: 1rem; box-shadow: 0 2px 8px rgba(0,0,0,0.04); transition: transform 0.2s; }
    .card:hover { transform: translateY(-2px); }
    .card-title { font-weight: 600; color: #5d4e37; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 8px; }
    .file-tag { font-size: 0.75rem; padding: 2px 8px; border-radius: 12px; font-weight: 600; margin-right: 8px; }
    .file-pdf { background: #ffe6e6; color: #b33; }
    .file-doc { background: #e6f2ff; color: #247; }
    .card-meta { color: #888; font-size: 0.875rem; margin-top: 0.5rem; }
    
    /* 问答模块样式 */
    .mod-qa-container { margin-top: 2rem; }
    .qa-list { padding: 1rem 1.5rem; display: grid; grid-template-columns: 1fr; gap: 12px; }
    .qa-card { background: #fff; border: 1px solid #f0ead6; border-radius: 12px; padding: 14px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
    .qa-q, .qa-a { margin-top: 8px; white-space: pre-wrap; line-height: 1.65; }
    .qa-q .tag, .qa-a .tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 12px; margin-right: 8px; }
    .qa-q .tag { background: #ffe6e6; color: #b33; }
    .qa-a .tag { background: #e6f2ff; color: #247; }
    .qa-meta { margin-top: 6px; color: #666; font-size: 12px; }
    @media (max-width: 768px) { .qa-list { padding: 0.8rem; } }
    
    /* 表格样式 */
    .mod-table-container { margin-top: 2rem; }
    .report-table { width: 100%; border-collapse: collapse; margin-bottom: 2rem; }
    .report-table th, .report-table td { border: 1px solid #f0ead6; padding: 0.75rem; text-align: left; }
    .report-table th { background: #f8f4e3; color: #5d4e37; font-weight: 600; }
    .report-table a { color: #8b7355; text-decoration: none; }
    .report-table a:hover { text-decoration: underline; }
    
    /* 响应式 */
    @media (max-width: 768px) {
        .company-container { padding: 0.8rem; }
        .report-table, .iwen-table { font-size: 0.875rem; }
        .company-header { flex-direction: column; text-align: center; }
    }

    .more-link { text-align:right; margin:1rem 0; }
    
    /* 分页器样式 - 极简版 */
    .pagination { 
        margin: 0.8rem 0; 
        padding: 0.6rem 0.8rem; 
        background: #f8f4e3; 
        border-radius: 6px; 
        box-shadow: 0 1px 2px rgba(0,0,0,0.08); 
    }
    
    .pagination-links { 
        display: flex; 
        justify-content: center; 
        align-items: center; 
        gap: 8px; 
        margin-bottom: 0.5rem; 
    }
    
    .page-link { 
        display: inline-block; 
        padding: 3px 6px; 
        background: #fff; 
        color: #8b7355; 
        text-decoration: none; 
        border: 1px solid #e0d5c7; 
        border-radius: 3px; 
        transition: all 0.2s; 
        min-width: 24px; 
        text-align: center; 
        font-weight: 500; 
        font-size: 0.8rem; 
    }
    
    .page-link:hover { 
        background: #8b7355; 
        color: #fff; 
        border-color: #8b7355; 
        transform: translateY(-1px); 
        box-shadow: 0 1px 2px rgba(139, 115, 85, 0.3); 
    }
    
    .page-info { 
        color: #5d4e37; 
        font-weight: 500; 
        font-size: 0.8rem; 
        padding: 3px 8px; 
        background: #fff; 
        border: 1px solid #e0d5c7; 
        border-radius: 3px; 
    }
    
    .page-jump { 
        text-align: center; 
        margin-top: 0.4rem; 
    }
    
    .jump-form { 
        display: inline-flex; 
        align-items: center; 
        gap: 4px; 
        background: #fff; 
        padding: 2px 6px; 
        border-radius: 3px; 
        border: 1px solid #e0d5c7; 
    }
    
    .jump-input { 
        width: 40px; 
        padding: 2px 4px; 
        border-radius: 3px; 
        border: 1px solid #ddd; 
        text-align: center; 
        font-size: 0.75rem; 
    }
    
    .jump-input:focus { 
        outline: none; 
        border-color: #8b7355; 
        box-shadow: 0 0 0 1px rgba(139, 115, 85, 0.2); 
    }
    
    .jump-button { 
        padding: 2px 6px; 
        background: #8b7355; 
        color: #fff; 
        border: none; 
        border-radius: 3px; 
        cursor: pointer; 
        font-size: 0.75rem; 
        font-weight: 500; 
        transition: background 0.2s; 
    }
    
    .jump-button:hover { 
        background: #6d5a42; 
    }
    
    /* 响应式设计 */
    @media (max-width: 768px) {
        .pagination { 
            padding: 0.4rem 0.6rem; 
        }
        
        .pagination-links { 
            gap: 6px; 
        }
        
        .page-link { 
            padding: 2px 4px; 
            min-width: 20px; 
            font-size: 0.75rem; 
        }
        
        .page-info { 
            font-size: 0.75rem; 
            padding: 2px 6px; 
        }
        
        .jump-form { 
            gap: 3px; 
        }
        
        .jump-input { 
            width: 35px; 
            font-size: 0.7rem; 
        }
        
        .jump-button { 
            font-size: 0.7rem; 
            padding: 2px 4px; 
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="company-container">
    <div class="company-header">
        {% if company.stock_image %}
            <img class="company-avatar" src="{{ company.stock_image }}" alt="{{ company.stock_name }}">
        {% else %}
            <div class="company-avatar"></div>
        {% endif %}
        <div class="company-info">
            <h2>{{ company.stock_name }} ({{ company.stock_code }})</h2>
            <p>市场: {{ company.market | default('未知') }}</p>
        </div>
    </div>

    {# 引入研报表格模块 #}
    {% include "mod_table.html" %}

    {# 引入问答模块 #}
    {% include "mod_qa.html" %}
</div>
{% endblock %}

{% block pagination %}
{# 分页已在 mod_table.html 中 #}
{% endblock %}

{% block extra_js %}
<script>
    // 时间戳转换为指定格式的日期
    function formatDate(ts) {
        if (!ts) return '';
        const v = parseInt(ts, 10);
        if (isNaN(v)) return '';
        const ms = v > 1e12 ? v : v * 1000;
        const d = new Date(ms);
        const y = d.getFullYear();
        const m = String(d.getMonth() + 1).padStart(2, '0');
        const da = String(d.getDate()).padStart(2, '0');
        const hh = String(d.getHours()).padStart(2, '0');
        const mm = String(d.getMinutes()).padStart(2, '0');
        const ss = String(d.getSeconds()).padStart(2, '0');
        return `${y}-${m}-${da} ${hh}:${mm}:${ss}`;
    }

    // 更新日期格式
    function updateDates() {
        // 报告表格时间
        document.querySelectorAll('.report-table td:nth-child(2)').forEach(td => {
            const raw = td.textContent.trim();
            const timestamp = parseInt(raw, 10);
            if (!isNaN(timestamp) && String(timestamp).length >= 10) {
                const ts = timestamp > 1e12 ? timestamp : timestamp * 1000;
                td.textContent = formatDate(ts);
            }
        });

        // 问答时间
        document.querySelectorAll('.q-time').forEach(el => {
            const ts = el.getAttribute('data-ts');
            const f = formatDate(ts);
            if (f) el.textContent = f;
        });
        document.querySelectorAll('.a-time').forEach(el => {
            const ts = el.getAttribute('data-ts');
            const f = formatDate(ts);
            if (f) el.textContent = f;
        });
    }

    window.addEventListener('DOMContentLoaded', updateDates);
</script>
{% endblock %}